﻿@using PagedList;
@using PagedList.Mvc;
@model IPagedList<Project_2._2.Models.LoaiXe>
@{
    ViewBag.Title = "Default";
    Layout = "~/Views/Shared/_AdminLayoutPage.cshtml";
}
<script>

    document.getElementById("carBrand").setAttribute("class", "activee")
</script>
<link href="~/Content/Admin-content-right.css" rel="stylesheet" />
<script src="~/Script/Jquery_Table_Sort/jquery-latest.js"></script>
<script src="~/Script/Jquery_Table_Sort/jquery.tablesorter.js"></script>

<script type="text/javascript">
    $(document).ready(function () {
        $("table").tablesorter({ sortList: [[0, 0]], headers: { 10: { sorter: false } } });
    });

</script>

<style>
    .search {
        width: 100%;
        height: 40px;
        padding: 10px 0 10px 10px;
        float: left;
    }
</style>

<div class="grid_12">
    <div class="block-border">
        <div class="block-header">
            Quản Lý Loại Xe
            @Html.ActionLink("Thêm Mới", "Create", "AdminTypeOfCar", null, new { @class = "button" })
        </div>
        <div class="block-content" style="overflow:scroll">

            <div class="search">

                @using (Html.BeginForm("Default", "AdminTypeOfCar", FormMethod.Post, new { id = "Form" }))
                {
                    List<SelectListItem> record = new List<SelectListItem>();
                    int macdinh = 0;
                    if (ViewBag.record != null)
                    {
                        macdinh = int.Parse(ViewBag.record);
                    }
                    else
                    {
                        macdinh = 1;
                    }
                    for (int i = 1; i < 4; i++)
                    {
                        if (macdinh == i)
                        { record.Add(new SelectListItem { Text = i + " Dòng", Value = i.ToString(), Selected = true }); }
                        else
                        { record.Add(new SelectListItem { Text = i + " Dòng", Value = i.ToString() }); }
                    }

                    <span>Hiển Thị </span> @Html.DropDownList("Record", record, new { @class = "select", onchange = "SelectedIndexChanged()" })

                    <span style="padding:0 10px 0 290px"> Từ Khóa </span> @Html.TextBox("KeyWord", null, new { @class = "Textbox", @placeholder = "Nhập từ khóa ..." })
                    List<SelectListItem> SearchBy = new List<SelectListItem>();
                    SearchBy.Add(new SelectListItem { Text = "Tên Loại Xe", Value = "TenLoaiXe", Selected = true });
                    <span> Tìm Theo </span>@Html.DropDownList("SearchBy", SearchBy, new { @class = "select" });

                    <input type="submit" value="Tìm Kiếm" />
                }

            </div>
            @if (Model.Count > 0)
{
    using (Html.BeginForm("Multi_Delete", "AdminTypeOfCar", FormMethod.Post))
    {
        <table class="tablesorter" cellpadding="0" cellspacing="0">
            <thead>
                <tr>
                    <th style="text-align:center" width="100px;">Chọn</th>
                    <th style="text-align:center" width="100px;">Mã Loại Xe</th>
                    <th style="text-align:center" width="300px;">Tên Loại Xe</th>
                    <th style="text-align:center">Mô Tả</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>

                @foreach (var lx in Model)
                {
                    <tr>
                        <td style="text-align:center"><input type="checkbox" name="multi_delete_loaixe" id="multi_delete_loaixe" value="@lx.LoaiXeId"></td>
                        <td style="text-align:center">@lx.LoaiXeId</td>
                        <td style="text-align:center">@lx.TenLoaiXe</td>
                        <td style="text-align:center">@lx.MoTa</td>
                        <td style="width:70px">
                            <a class="tableActionButton edit" rel="tooltip-top" title="Cập Nhật" href="@Url.Action("Update", "AdminTypeOfCar", new { id = lx.LoaiXeId })"></a>

                            <a class="tableActionButton delete" rel="tooltip-top" title="Xóa" href="../AdminTypeOfCar/Delete/@lx.LoaiXeId" onclick="return DeleteConfirm()"></a>
                        </td>
                    </tr>
                }
            </tbody>
        </table>
                             <input type="submit" value=" Xóa Tùy Chọn " class="MyButton" style="margin:13px 0 0 10px; float:left" onclick="return DeleteConfirm()" />
    }
                  <table cellpadding="0" cellspacing="0" style="border-top:none; margin:5px 0px 5px 0; float:right;   ">
                    <tr>
                        <td style="width:65px; text-align:right; font-weight:bold;padding-top:2px ">
                            <span style="border: 1px solid #808080; border-right: none; padding: 7px 15px; margin-top: 10px; border-radius: 4px 0 0 4px; background-color: #428bca; color:#ffffff"> Trang</span>
                        </td>
                        <td>@Html.PagedListPager(Model, page => Url.Action("Default", new { page, rd = ViewBag.record }), new PagedListRenderOptions() { LinkToFirstPageFormat = "<<", LinkToPreviousPageFormat = " < ", LinkToNextPageFormat = " > ", LinkToLastPageFormat = ">>" })</td>
                    </tr>
                </table>
            }
            else
            {
                <span>&nbsp &nbsp Không có dữ liệu...!</span>
            }
        </div>
    </div>
</div>
<script>

    function DeleteConfirm() {
        if (confirm("Bạn có thật sự muốn xóa không?"))
            return true;
        else
            return false;
    }

    function SelectedIndexChanged() {
        $('#Form').submit();
    }
</script>
@if (!string.IsNullOrEmpty(ViewBag.alert))
{
    <input id="alert" type="hidden" value="@ViewBag.alert" />
    <script type="text/javascript">
        var a = document.getElementById("alert").value;
        alert(a);
    </script>
}